from django import template
from django.conf import settings

register = template.Library()

font_size = 13

@register.simple_tag
def div(text, left, top):
    if not text: text=""
    return '<div style="position: absolute;font-family:arial;font-size:%s; left: %scm; top: %scm">%s</div>' % (font_size,left-0.2, top-0.65, text)

@register.simple_tag
def div_fecha(text, left, top):
	fecha = text.strftime("%d/%m/%Y")
	return div(fecha, left, top)

@register.simple_tag
def init_rows(obj, y, loop):
	obj.init_rows(y,loop)
	return ""
	
@register.simple_tag
def next_row(obj):
	obj.next_row()
	return ""
	
@register.simple_tag
def div_row(obj,text, left):
    return div(text, left, obj.y)



@register.simple_tag
def end_rows(obj):
	obj.end_rows()
	return ""

@register.simple_tag
def div_float(text, left, top):
	text = "%.2f" % float(text)
	return div(text, left - len(text)*0.23 + 0.1, top)


@register.simple_tag
def div_float_cuad(text, left, top):
	text = "%.4f" % float(text)
	return div(text, left - len(text)*0.23 + 0.1, top)

@register.simple_tag
def div_float_row(obj,text, left, ):
    return div_float(text, left, obj.y)



@register.simple_tag
def div_float_cuad_row(obj,text, left, ):
    return div_float_cuad(text, left, obj.y)


@register.simple_tag
def div_width(text, left, top, width):
    if not text: text=""
    return '<div style="position: absolute;font-family:arial;font-size: %s; left: %scm; top: %scm; width: %scm;">%s</div>' % (font_size,left-0.2, top-0.65, width, text)

@register.simple_tag
def div_width_jus(text, left, top, width):
    if not text: text=""
    return '<div style="position: absolute;font-family:arial;font-size: %s;text-align:justify; left: %scm; top: %scm; width: %scm;line-height: 15pt">%s</div>' % (font_size,left-0.2, top-0.65, width, text)

@register.simple_tag
def div_width_row(obj,text, left, width):
    return div_width(text, left, obj.y, width)

@register.simple_tag
def div_width_jus_row_adv(obj,text, left, width):
    a = obj.y
    obj.advance_to_reng(text)
    return div_width_jus(text, left, a, width)

